/*
  The MIT License
  
  Copyright (c) 2010 smath-view project
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/
package pl.smath.renderer.model.sign;

import gwt.g2d.client.graphics.Surface;
import pl.smath.renderer.utils.Cursor;
import pl.smath.renderer.utils.Rectangle;

/**
 * AbstractSign - represents a certain sign to be rendered.
 * 
 * @author Damian Rodziewicz
 *
 */
public abstract class AbstractSign {
	private Rectangle rectangle;
	private String font;
	private Double fontHeight;
	private Double space;
	private final Double brushSize = 1d;
	private Double signWidth;
	
	public AbstractSign() {
		this.rectangle = new Rectangle();
		this.signWidth = 0d;
	}
	
	public abstract void render(Surface canvas, Cursor cursor);
	
	/**
	 * get the element's height
	 * @return height
	 */
	public Double getHeight() {
		return this.rectangle.getHeight();
	}
	
	/**
	 * get the element's width
	 * @return width
	 */
	public Double getWidth() {
		return this.rectangle.getWidth();
	}
	
	/**
	 * set the element's font
	 * @param font
	 * @param fontHeight
	 */
	public void setFont(String font, Double fontHeight) {
		this.fontHeight = fontHeight;
		this.font = font;
		this.space = new Double(Math.round(0.35d * this.fontHeight));
		update();
	}
	
	/**
	 * return the space between the rendered sign and other views
	 * @return
	 */
	public Double getSpace() {
		return this.space;
	}
	
	/**
	 * return the font height
	 * @return font height
	 */
	public Double getFontHeight() {
		return this.fontHeight;
	}
	
	/**
	 * return the font with it's height
	 * @return
	 */
	public String getFont() {
		return this.fontHeight + "px " + this.font;
	}
	
	/**
	 * get the thickness
	 * @return brush size
	 */
	public Double getBrushSize() {
		return this.brushSize;
	}
	
	/**
	 * set the space between sign and other terms
	 * @param space
	 */
	public void setSpace(Double space) {
		this.space = space;
		update();
	}
	
	/**
	 * update the width and height
	 */
	public abstract void update();
	
	/**
	 * set width of the sign
	 * @param width
	 */
	public void setSignWidth(Double width) {
		this.signWidth = width;
	}
	
	/**
	 * the width of the sign
	 * @return
	 */
	public Double getSignWidth() {
		return this.signWidth;
	}
	
	/**
	 * set width of the sign
	 * @param width
	 */
	public void setWidth(Double width) {
		this.rectangle.setWidth(width);
	}
	
	/**
	 * set height of the sign
	 * @param height
	 */
	public void setHeight(Double height) {
		this.rectangle.setHeight(height);
	}
}
